﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KAImage.Config;
using LogLib;

namespace KAImage.AlgorAction
{
    public class BlurSharpenAction : IAlgorAction
    {
        private string _error = "";

        public string ErrorMessage
        {
            get { return _error; }
        }

        private BlurSharpenOption _option = new BlurSharpenOption();
    
        private bool _enabled = false;
        public bool Enabled
        {
            private set
            {
                _enabled = value;
            }
            get
            {
                return _enabled;
            }
        }

        private int _callIndex = 3;
        public int CallIndex
        {
            private set 
            {
                _callIndex = value;
            }
            get 
            {
                return _callIndex;
            }
        }

        public BlurSharpenAction()
        {
            _option = KAConfigs.BlurSharpen;
        }

        public bool DoAction(System.Drawing.Bitmap source)
        {
            try
            {
                if (_option.GaussianRadius > 0)
                {
                    source.GaussianBlur(_option.GaussianRadius, false);
                }
                if (_option.USMRadius > 0 || _option.USMDegree > 0)
                {
                    source.UsmSharpen(_option.USMRadius, _option.USMDegree);
                }
                return true;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                Log.WriteAsync(ex.ToString());
                return false;
            }
          
        }
    }
}
